﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Achievement.BLL.Provider;
using Achievement.DataModels;
using System.Dynamic;
using Achievement.Web.Common;

namespace Achievement.Web.Controllers
{
    [Authorize]
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            int total = 0;
            List<Achievements> newlist = AchievementsProvider.Instance.GetAchievementsList(string.Empty,0,null,1,8,"desc","ID",out total);
            //List<Achievements> hotlist = AchievementsProvider.Instance.GetAchievementsList(string.Empty, 0, null, 1, 8, "desc", "Count", out total);
            var myFolders = FolderProvider.Instance.GetFidsByUid(UserInfo.CurrentUser.ID);
            List<VFolder> newFolders = FolderProvider.Instance.GetVFolderTreeByIds(myFolders);
            List<VSumAchievementFolders> vsaf = new List<VSumAchievementFolders>();
            if (UserInfo.ValidataRole(1))
            {
                vsaf = FolderProvider.Instance.SumAchievementByFolders(newFolders, true).OrderByDescending(v => v.FID).Take(6).ToList();
            }
            else
            {
                vsaf = FolderProvider.Instance.SumAchievementByFolders(newFolders).OrderByDescending(v => v.FID).Take(6).ToList();
            }
            List<VComment_A_U> comment = AchievementsProvider.Instance.GetCAUTop(2);
            dynamic home = new ExpandoObject();
            home.NewAchievements = newlist;
            //home.HotAchievements = hotlist;
            home.HotFolder = vsaf;
            home.NewComment = comment;
            return View(home);
        }

    }
}
